//
//  HUMainTabBarController.swift
//  weiboProject
//
//  Created by hehuan on 16/7/18.
//  Copyright © 2016年 hehuan. All rights reserved.
//

import UIKit

class HUMainTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let mainTabBar = HUTabBarView()
        
        mainTabBar.composeCallBack = { () -> Void in
            print("我在控制器里面知道加号按钮点击了")
        }
        
        self.setValue(mainTabBar, forKey: "tabBar")
        
        addChildViewController()
        
    }
    func addChildViewController() {
        let homeController=HUHomeTableController()
        addchildviewcontrollers(homeController, title: "首页", imageName: "tabbar_home")
        
        let massageController = HUMassageTableController()
        addchildviewcontrollers(massageController, title: "消息", imageName: "tabbar_message_center")
        
        let discoverController = HUDiscoverTableController()
        addchildviewcontrollers(discoverController, title: "发现", imageName: "tabbar_discover")
        
        let profileController = HUProfileTableController()
        addchildviewcontrollers(profileController, title: "我", imageName: "tabbar_profile")
    }
    
    func addchildviewcontrollers(controller: UIViewController, title: String,imageName: String) {
        
        controller.title = title
        
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected)
        
        controller.tabBarItem.image = UIImage(named: imageName)
        let name = imageName + "_selected"
        
        controller.tabBarItem.selectedImage = UIImage(named: name)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        self.addChildViewController(UINavigationController(rootViewController: controller))
        
    }

}
